package file

import (
	"path"

	"gitee.com/mkwchecking/sr-core/log/ilog"
	"github.com/natefinch/lumberjack"
)

// var _ log.Writer = (*File)(nil)

func init() {
	ilog.RegisterLogWriter(ilog.File, New)
}

func New(cfg *ilog.Config) (ilog.Writer, error) {

	out := &lumberjack.Logger{
		Filename:   path.Join(cfg.Path, cfg.FileName),
		MaxSize:    cfg.MaxSize,
		MaxAge:     cfg.MaxAge,
		MaxBackups: cfg.MaxBackup,
		Compress:   true,
		LocalTime:  true,
	}
	return out, nil
}

/*
type File struct {
	cfg    log.Config
	writer io.Writer
}

// Enable implements log.Writer.
func (f *File) Enable(level log.Level) bool {
	return true
}

// Write implements log.Writer.
func (f *File) Write(p []byte) (n int, err error) {
	return f.writer.Write(p)
}
*/
